package cn.cupk.corporateshuttlemanagesystem.mapper;

import cn.cupk.corporateshuttlemanagesystem.pojo.Reservations;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;
@Mapper
public interface ReservationInformationMapper {
    @Select({
            "<script>",
            "SELECT reservations.*, stops.name as stopName, routes.name as routeName FROM reservations",
            "LEFT JOIN routes ON reservations.route_id = routes.route_id",
            "LEFT JOIN stops ON reservations.stop_id = stops.stop_id",
            "<where>",
            "<if test='name != null'>",
            "AND stops.name LIKE CONCAT('%', #{name}, '%')",
            "</if>",
            "<if test='userId != null'>",
            "AND reservations.user_id = #{userId}",
            "</if>",
            "</where>",
            "</script>"
    })
    List<Reservations> page(String name, Integer userId);

}
